<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title><!--{$lang.page.index.title}--></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/lay/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/lay/layui/index.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-text-item" style="text-align: center;"><b><!--{$lang.page.public.control}--></b></div>
     <div class="layui-card">
      <div class="layui-form layuiadmin-card-header-auto">
        <div class="layui-text-item">
          <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.name}--></label>
            <div class="layui-text-inline">
              <!--{$datainfo.title}-->
            </div>
          </div>
          <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.agent}--></label>
            <div class="layui-text-inline">
              <!--{$datainfo.username}-->
            </div>
          </div>
          <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.status}--></label>
            <div class="layui-text-inline">
              <!--{if $datainfo.status==1}-->
              <a class="layui-btn layui-btn-xs"><!--{$lang.page.table.normal}--></a>
              <!--{elseif $datainfo.status==2}-->
              <a class="layui-btn layui-btn-green layui-btn-xs"><!--{$lang.page.table.finish}--></a>
              <!--{elseif $datainfo.status==3}-->
              <a class="layui-btn layui-btn-primary layui-btn-xs"><!--{$lang.page.table.close}--></a>
              <!--{/if}-->
            </div>
          </div>
          <div class="layui-text-line">
            <label class="layui-text-label"></label>
            <div class="layui-text-inline">
              <a class="layui-btn layui-btn-xs layui-btn-danger" id="getconf"><!--{$lang.page.public.update}--> <!--{$lang.page.public.parameter}--></a>
            </div>
          </div>

          <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.method}--></label>
            <div class="layui-text-inline">
              <!--{if $datainfo.auto eq 1}--><!--{$lang.page.table.auto}--><!--{else if $datainfo.auto eq 2}--><!--{$lang.page.table.noauto}--><!--{else}-->none<!--{/if}-->
            </div>
          </div>
          
        </div>
      </div>
      <div class="layui-card" <!--{if !$info}-->style="display: none;"<!--{/if}-->>
      <div class="layui-form layuiadmin-card-header-auto">
        <div class="layui-text-item">
          <label class="layui-text-label" id="banner"></label>
          <div class="layui-text-line">
            <div class="layui-text-inline" id="timer" endtime="<!--{$info.starttime}-->" timelong="<!--{$info.timelong}-->"></div>
            <div class="layui-text-inline" id="oldprice" style="width:150px"></div>
            <div class="layui-text-inline" id="newprice" style="width:150px"></div>
            <!-- <div class="layui-text-inline" id="rate" style="width:150px"></div> -->
            <div class="layui-text-inline" id="info"></div>
          </div>
        </div>
        </div>
      </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body" style="padding: 15px;">
        <form name="addItem" method="post" lay-filter="component-form-group" class="layui-form">
          <input type="hidden" value="<!--{$datainfo.id}-->" name="id">
          <input type="hidden" value="<!--{$datainfo.aid}-->" name="aid">
          <input type="hidden" value="<!--{$datainfo.title}-->" name="title">
          <input type="hidden" value="<!--{$datainfo.proid}-->" name="proid">
          <input type="hidden" value="<!--{$datainfo.procode}-->" name="procode">
          <input type="hidden" value="<!--{$datainfo.run}-->" name="run">
          <input type="hidden" value="<!--{$datainfo.runtime}-->" name="runtime">

          <div class="layui-form-item">
             <label class="layui-form-label"><!--{$lang.page.table.point}--> <!--{$lang.page.public.control}--></label>
              <div class="layui-inline" id="submue"  style="width:80%;">

                <table class="layui-table" lay-filter="table">
                <thead>
                    <tr>
                        <td width="12%"><!--{$lang.page.table.name}--></td>
                        <td width="20%"><!--{$lang.page.public.min}-->(<!--{$lang.page.public.multiple}-->)</td>
                        <td width="20%"><!--{$lang.page.public.max}-->(<!--{$lang.page.public.multiple}-->)</td>
                        <td width="18%"><!--{$lang.page.table.direction}--></td>
                        <td width="15%"><!--{$lang.page.public.minbeat}--></td>
                        <td width="15%"><!--{$lang.page.public.numsize}--></td>
                    </tr>
                </thead>
                <tbody>
                     <tr>
                     <td><!--{$lang.page.table.closeing}--></td>
                     <td><input type="text" name="point[min]" value="<!--{$datainfo.point.min}-->" lay-verify="min" placeholder="10" autocomplete="off" class="layui-input" /></td>
                     <td><input type="text" name="point[max]" value="<!--{$datainfo.point.max}-->" lay-verify="max" placeholder="30" autocomplete="off" class="layui-input" /></td>
                     <td><input type="radio" name="point[trend]" value="1" title="<!--{$lang.page.table.upwin}-->" <!--{if $datainfo.point.trend eq 1}--> checked<!--{/if}-->>&nbsp;&nbsp;<input type="radio" name="point[trend]" value="2" title="<!--{$lang.page.table.downwin}-->" <!--{if $datainfo.point.trend eq 2}--> checked<!--{/if}-->></td>
                     <td><input type="text" name="point[unit]" value="<!--{$datainfo.point.unit}-->" lay-verify="unit" placeholder="1-3" autocomplete="off" class="layui-input" readonly/></td>
                     <td><input type="text" name="point[length]" value="<!--{$datainfo.point.length}-->" lay-verify="length" placeholder="1-3" autocomplete="off" class="layui-input" readonly/></td>
                     </tr>
                  </tbody>
                </table>
              </div>
          </div>

          <div class="layui-form-item">

              <div class="layui-inline">
                <label class="layui-form-label"><!--{$lang.page.table.method}--></label>
                <div class="layui-input-block">
                  <input type="radio" name="auto" lay-filter="brickAuto" value="1" title="<!--{$lang.page.table.auto}-->" <!--{if $datainfo.auto eq 1}--> checked<!--{/if}-->>&nbsp;&nbsp;<input type="radio" name="auto" lay-filter="brickAuto" value="2" title="<!--{$lang.page.table.noauto}-->" <!--{if $datainfo.auto eq 2}--> checked<!--{/if}-->>
                </div>
              </div>

              <div class="layui-inline">
                <label class="layui-form-label"><!--{$lang.page.table.timelong}-->（s）</label>
                <div class="layui-input-block">
                  <input type="text" name="timelong" class="layui-input" lay-verify="timelong" value="<!--{$datainfo.timelong}-->" >
                </div>
              </div>
              <div class="layui-inline showtime" <!--{if $datainfo.auto eq 2}-->style="display: none;"<!--{/if}-->>
                <label class="layui-form-label"><!--{$lang.page.public.start}--> <!--{$lang.page.table.time}--></label>
                <div class="layui-input-block">
                   <input type="text" name="starttime" class="layui-input" id="test12" value="<!--{$datainfo.starttime}-->" placeholder="yyyy-MM-dd HH:mm:ss">
                </div>
              </div>
               <div class="layui-inline showbtn" <!--{if $datainfo.auto eq 1  || $datainfo.run eq 1 }-->style="display: none;"<!--{/if}-->>
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                   <button type="button" class="layui-btn" lay-submit lay-filter="change"><!--{$lang.page.public.start}--></button>
                </div>
              </div> 
          </div>
                  
          <div class="layui-form-item layui-layout-admin">
            <div>
              <div class="layui-footer" style="left: 0;">
                <button type="button" class="layui-btn showtime" <!--{if $datainfo.auto eq 2 || $datainfo.run eq 1}-->style="display: none;"<!--{/if}--> lay-submit lay-filter="submit" ><!--{$lang.page.public.submit}--></button>
                <button type="button" class="layui-btn" <!--{if $datainfo.run eq 0}-->style="display: none;"<!--{/if}--> lay-submit lay-filter="edit" ><!--{$lang.page.public.change}--></button>
                <button type="button" class="layui-btn" <!--{if $datainfo.run eq 0}-->style="display: none;"<!--{/if}--> lay-submit lay-filter="del" ><!--{$lang.page.public.stop}--></button>
                <button type="button" class="layui-btn layui-btn-primary" onClick="xadmin.close();" ><!--{$lang.page.table.back}--></button>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
<script src="/static/lay/layui/layui.js"></script>
  <script type="text/javascript">
    layui.config({
     base: '/static/lay/' //静态资源所在路径
   }).extend({
     xadmin: 'lib/xadmin' //弹窗
   }).use(['jquery', 'layer','xadmin', 'form', 'element','laydate'], function(){
    var $ = layui.$ //引用jq
    var layer = layui.layer; //独立版的layer无需执行这一句
    var form = layui.form;
     form.render(null, 'component-form-group');
     /* 自定义验证规则 */
    form.verify({
      title: function(value){
        if(value.length < 1){
          return '<!--{$lang.page.table.name}--> <!--{$lang.page.public.nocontent}-->';
        }
      }
      ,double: function(value){
        if(/^\d+$/.test(value)==false && /^\d+\.\d+$/.test(value)==false)
        {
            return '<!--{$lang.page.public.paraerror}-->';
        }
      }
    });
    
    $(document).on('click', '#getconf', function() {
        var id = $("input[name='id']").val();
        layer.alert('<!--{$lang.page.public.getproagain}-->', {
            offset:'100px'
            , closeBtn: 1 // 是否显示关闭按钮
            , anim: 1 //动画类型
            , btn: ['<!--{$lang.page.table.confirm}-->', '<!--{$lang.page.table.cancel}-->'] //按钮
            , icon: 6 // icon
            , yes: function () {
                $.post('getconf',{'id':id},function(res){
                    if(res.code == 200){
                        layer.msg(res.msg);
                        setTimeout(() => {
                            window.location.reload();
                        }, 1000);
                    }else{
                        layer.msg(res.msg);
                    }
                })
            }
        });
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    
    form.on('submit(submit)', function (data) {
          $.post('#',data.field,function(res){
              if(res.code == 200){
                  layer.msg(res.msg);
                  setTimeout(() => {
                      window.location.reload();
                      // xadmin.close();
                  }, 1000);
              }else{
                  layer.msg(res.msg);
              }
          })
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    form.on('submit(edit)', function (data) {
          $.post('#',data.field,function(res){
              if(res.code == 200){
                  layer.msg(res.msg);
                   setTimeout(() => {
                      window.location.reload();
                  }, 1000);
              }else{
                  layer.msg(res.msg);
              }
          })
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    layui.laydate.render({
        elem: '#test12',
        type: 'datetime'
    });

    form.on('radio(brickType)', function(data){
        var p = data.value;
        if( p == 1 ){
            $('.showds').show();
            $('.showyll').hide();
            
        }else if( p == 2 ){
            $('.showds').hide();
            $('.showyll').show();
        }
        form.render();
    });

    form.on('radio(brickAuto)', function(data){
        var p = data.value;
        if( p == 1 ){
            $('.showtime').show();
            $('.showbtn').hide();
            
        }else if( p == 2 ){
            $('.showtime').hide();
            $('.showbtn').show();
        }
        form.render();
    });

    form.on('submit(del)', function (data) {
        layer.alert('<!--{$lang.page.public.stopconinfo}-->', {
            offset:'100px'
            , closeBtn: 1 // 是否显示关闭按钮
            , anim: 1 //动画类型
            , btn: ['<!--{$lang.page.table.confirm}-->', '<!--{$lang.page.table.cancel}-->'] //按钮
            , icon: 6 // icon
            , yes: function () {
                $.post('diskdel',{
                      'procode':$('input[name="procode"]').val(),
                      'aid':$('input[name="aid"]').val()
                    },function(res){
                    if(res.code == 200){
                        layer.msg(res.msg);
                        setTimeout(() => {
                            window.location.reload();
                        }, 1000);
                    }else{
                        layer.msg(res.msg);
                    }
                })
            }
        });
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    
    form.on('submit(change)', function (data) {
          if(data.field.run==1){
            layer.alert('<!--{$lang.page.public.resetconinfo}-->', {
                offset:'100px'
                , closeBtn: 1 // 是否显示关闭按钮
                , anim: 1 //动画类型
                , btn: ['<!--{$lang.page.table.confirm}-->', '<!--{$lang.page.table.cancel}-->'] //按钮
                , icon: 6 // icon
                , yes: function () {
                    $.post('#',data.field,function(res){
                        if(res.code == 200){
                            layer.msg(res.msg);
                            setTimeout(() => {
                                window.location.reload();
                                // xadmin.close();
                            }, 1000);
                        }else{
                            layer.msg(res.msg);
                        }
                    })
                }
            });
          }else{
              $.post('#',data.field,function(res){
                  if(res.code == 200){
                      layer.msg(res.msg);
                      setTimeout(() => {
                          window.location.reload();
                          // xadmin.close();
                      }, 1000);
                  }else{
                      layer.msg(res.msg);
                  }
            })
          }
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    $('#timer').ready(function(){
        var endtime =  $('#timer').attr('endtime');
        var timelong =  $('#timer').attr('timelong');
        var countdownElement = document.getElementById("timer");
        if(endtime>0){
          let setInt=setInterval(() => {
              var now = new Date().getTime(); // 当前时间
              var distance = Math.floor((endtime*1000+timelong*1000 - now)/1000); // 距离结束日期还有多少时间
              if(distance<0){
                clearInterval(setInt); // 如果已经到达或超过了结束日期，清除定时器并隐藏倒计时元素
                countdownElement.style.display = "none";
                window.location.reload();
                return;
              }else{
                if(distance>timelong){
                  var times = distance-timelong;
                  var d = parseInt(times / 60 / 60 / 24); d = d < 10 ? '0' + d : d;
                  var h = parseInt(times / 60 / 60 % 24);h = h < 10 ? '0' + h : h;
                  var m = parseInt(times / 60 % 60); m = m < 10 ? '0' + m : m;
                  var s = parseInt(times % 60); s = s < 10 ? '0' + s : s;
                  countdownElement.innerHTML = '<!--{$lang.page.public.start}--> <!--{$lang.page.table.time}-->：<font color="#2b7100">' + d + ' 天 ' + h + ' : ' + m + ' : ' + s + '</font>'; // 更新倒计时内容
                }else{
                  countdownElement.innerHTML = '<!--{$lang.page.public.control}--> <!--{$lang.page.table.time}-->：<font color="#ab7e00">' + distance + 's</font>'; // 更新倒计时内容
                  $.post('diskinfo',{
                      'procode':$('input[name="procode"]').val(),
                      'aid':$('input[name="aid"]').val()
                    },function(res){
                      if(res.code == 200){
                         document.getElementById("banner").textContent = '<!--{$lang.page.public.gorun}-->';
                         document.getElementById("oldprice").innerHTML = '<!--{$lang.page.table.nowprice}-->：<font color="#21a700">' + res.data.oldprice + '</font>';
                         document.getElementById("newprice").innerHTML = '<!--{$lang.page.public.control}--> <!--{$lang.page.table.nowprice}-->：<font color="#ff0000">'+res.data.newprice+'</font>';
                         // document.getElementById("rate").innerHTML = '盈利率变量：<font color="#0084ab">'+res.data.rate+'</font>';
                         document.getElementById("info").innerHTML = '<!--{$lang.page.public.control}--> <!--{$lang.page.table.notes}-->：'+res.data.info+'';
                         $('input[name="runtime"]').val(distance);
                      }else{
                         layer.msg(res.msg);
                      }          
                  })
                }
                return;
              }
          },1000)
        }else{
          countdownElement.style.display = "none";
      }  
    });

  });

  </script>
</body>
</html>

